<?php


/*
 * Edit by shengxin
 * Click nbfs://nbhost/SystemFileSystem/Templates/Scripting/PHPClass.php to edit this template
 */
namespace api\mall\task;

use api\portal\model\UserModel;
/**
 * Description of BaseTask
 *
 * @author PC
 */
class BaseTask {
    public $reward = 0;
    protected $TaskName;
    public function __construct($name) {
        $this->TaskName = $name;
    }
    public function check_comp($task){
        echo 'implements check_comp';
    }
    public function get_reward($uid,$cfg){
        $reward = $cfg['task_reward'];
        if(is_array($reward) && isset($reward['score'])){
            $score = $reward['score'];
        }else{
            $score = $reward;
        }
        if(empty($cfg['task_name'])){
            $cfg['task_name'] = $this->TaskName;
        }
        $desc = '完成任务:'.$cfg['task_name'].',领取任务奖励';
        $model = new UserModel();
        $model->add_score($uid, $score, $desc,'task');
        $model->addTaskLog($uid, $score, $desc);
        $this->reward = $score;
    }
}
